package com.malljelly.study.config;


import com.malljelly.study.interceptor.BaseInterceptor;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Configuration;
import org.springframework.web.servlet.config.annotation.DefaultServletHandlerConfigurer;
import org.springframework.web.servlet.config.annotation.InterceptorRegistry;
import org.springframework.web.servlet.config.annotation.ResourceHandlerRegistry;
import org.springframework.web.servlet.config.annotation.WebMvcConfigurationSupport;

/**
 * springmvc的拦截器加入到拦截器的注册器中
 */
@Configuration
public class WebMvcConfg extends WebMvcConfigurationSupport {

    @Autowired
    private BaseInterceptor baseInterceptor;

    /**
     * springmvc的拦截器加入到拦截器的注册器中
     * @param registry
     */
    @Override
    public void addInterceptors(InterceptorRegistry registry) {
		registry.addInterceptor(baseInterceptor);
    }

    /**
     * swagger-ui.html开“绿灯”添加例外。
     * @param registry
     */
    @Override
    public void addResourceHandlers(ResourceHandlerRegistry registry) {
        registry.addResourceHandler("swagger-ui.html")
                .addResourceLocations("classpath:/META-INF/resources/");
        registry.addResourceHandler("/webjars")
                .addResourceLocations("classpath:/META-INF/resources/webjars/");
    }
    @Override
    public void configureDefaultServletHandling(DefaultServletHandlerConfigurer configurer) {
        configurer.enable();
    }

}
